package com.Studen.controller;

import com.Studen.bean.Score;
import com.Studen.bean.User;
import com.Studen.servlet.StudentServlet;
import com.Studen.servlet.StudentServletMpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet("/StudentLogin")
public class StudentController extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /**
         *  获取登录的姓名和密码
         *
         *  将姓名和密码封装在user对象后交给后台进行校验
         * */
        String name=request.getParameter("u_name");
        String pwd=request.getParameter("u_password");

        User user = new User();
        user.setU_pwd(pwd);
        user.setU_name(name);
        StudentServlet s=new StudentServletMpl();
        List<Score>u =s.StudentLogin(user);
        if (u.isEmpty()){
            //没有找到这位同学 提示用户名或者密码有误
            request.setAttribute("ts","用户名或者密码有误");
            request.getRequestDispatcher("TeacherLogin.jsp").forward(request,response);
        }
        else {
            request.setAttribute("score",u);
            request.getRequestDispatcher("StudentScore.jsp").forward(request,response);
        }
    }
}
